import fs from "fs-extra";
import { remote, app } from "electron";
import path from "path";
import RichClientLog from "@anyshare/common/lib/utils/logHelper";

const log = new RichClientLog();

export function getSyncDiskName() {
    let zhcnSyncDiskName: string = "AnyShare云盘";
    let zhtwSyncDiskName: string = "AnyShare雲盤";
    let enusSyncDiskName: string = "AnyShare Folder";
    try {
        const oemFilePath = path.resolve(
            process.type === "browser" ? app.getAppPath() : remote.app.getAppPath(),
            process.env.NODE_ENV === "development" ? "../../public/oem.json" : "./public/oem.json"
        );
        const jsonObject = JSON.parse(fs.readFileSync(oemFilePath, "utf-8"));
        return {
            zhcn: jsonObject.zhcnSyncDiskName ? jsonObject.zhcnSyncDiskName : zhcnSyncDiskName,
            zhtw: jsonObject.zhtwSyncDiskName ? jsonObject.zhtwSyncDiskName : zhtwSyncDiskName,
            enus: jsonObject.enusSyncDiskName ? jsonObject.enusSyncDiskName : enusSyncDiskName,
        };
    } catch (error) {
        log.error(error);
        return {
            zhcn: zhcnSyncDiskName,
            zhtw: zhtwSyncDiskName,
            enus: enusSyncDiskName,
        };
    }
}
